package com.wangan.wanganpush.xml;

import com.wangan.wanganpush.model.Trajectory;
import com.wangan.wanganpush.utils.AppConstants;

import java.util.List;

/*
 * 轨迹类信息
 * */
public class TrajectoryXml {

    private static String number = "VEHICLETRACK";

    public static String parseXml(List<Trajectory> urList,String messageCode)

    {
        if (urList == null || urList.size() == 0) return null;

        try {
            StringBuffer sb = new StringBuffer();
            sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>  <MESSAGE>");
            sb.append("<DATASET name=\"WA_COMMON_010000\">  <DATA>");
            sb.append("<ITEM key=\"H010001\" val=\"" + AppConstants.applicationCoding + "\"/>");
            sb.append("<ITEM key=\"I010014\" val=\"" + messageCode + "\"/>");
            sb.append("<ITEM key=\"I010031\" val=\"" + number + "\"/>");
            sb.append("<ITEM key=\"I010013\" val=\"" + 3 + "\"/>");
            sb.append("</DATA> </DATASET> ");

            sb.append("<DATASET name=\"WA_COMMON_010022\">");

            for (int i = 0; i < urList.size(); i++) {
                Trajectory trajectory = urList.get(i);
                sb.append("<DATA>");
                if (trajectory.getOrderNo() != null) {
                    sb.append("<ITEM key=\"H090001\" val=\"" + trajectory.getOrderNo() + "\"/>");
                }

                if (trajectory.getDriverAccount() != null) {
                    sb.append("<ITEM key=\"H230039\" val=\"" + trajectory.getDriverAccount() + "\"/>");
                }

                if (trajectory.getDriverId() != null) {
                    sb.append("<ITEM key=\"H230040\" val=\"" + trajectory.getDriverId() + "\"/>");
                }

                if (trajectory.getPassengerAccount() != null) {
                    sb.append("<ITEM key=\"H230058\" val=\"" + trajectory.getPassengerAccount() + "\"/>");
                }

                if (trajectory.getPassengerId() != null) {
                    sb.append("<ITEM key=\"H230057\" val=\"" + trajectory.getPassengerId() + "\"/>");
                }

                if (trajectory.getVehicleId() != null) {
                    sb.append("<ITEM key=\"C030009\" val=\"" + trajectory.getVehicleId() + "\"/>");
                }

                if (trajectory.getCurrentTimeDay() != null) {
                    sb.append("<ITEM key=\"H230059\" val=\"" + trajectory.getCurrentTimeDay() + "\"/>");
                }

                if (trajectory.getDetailedLocation() != null) {
                    sb.append("<ITEM key=\"H230060\" val=\"" + trajectory.getDetailedLocation() + "\"/>");
                }

                if (trajectory.getTerminalMacAddress() != null) {
                    sb.append("<ITEM key=\"C040002\" val=\"" + trajectory.getTerminalMacAddress() + "\"/>");
                }

                if (trajectory.getMobileTerminalImel() != null) {
                    sb.append("<ITEM key=\"C050001\" val=\"" + trajectory.getMobileTerminalImel() + "\"/>");
                }

                if (trajectory.getMobileTerminalImsl() != null) {
                    sb.append("<ITEM key=\"B020007\" val=\"" + trajectory.getMobileTerminalImsl() + "\"/>");
                }

                if (trajectory.getClientHardwareString() != null) {
                    sb.append("<ITEM key=\"C040003\" val=\"" + trajectory.getClientHardwareString() + "\"/>");
                }

                if (trajectory.getCurrentLongitude() != null) {
                    sb.append("<ITEM key=\"H230061\" val=\"" + trajectory.getCurrentLongitude() + "\"/>");
                }

                if (trajectory.getCurrentLatitude() != null) {
                    sb.append("<ITEM key=\"H230062\" val=\"" + trajectory.getCurrentLatitude() + "\"/>");
                }

                if (trajectory.getIpAddress() != null) {
                    sb.append("<ITEM key=\"F020004\" val=\"" + trajectory.getIpAddress() + "\"/>");
                }

                if (trajectory.getIpPort() != null) {
                    sb.append("<ITEM key=\"F020006\" val=\"" + trajectory.getIpPort() + "\"/>");
                }

                if (trajectory.getTrajectoryType() != null) {
                    sb.append("<ITEM key=\"H230063\" val=\"" + trajectory.getTrajectoryType() + "\"/>");
                }

                sb.append("</DATA>");
            }

            sb.append("</DATASET>");
            sb.append("</MESSAGE>");


            return sb.toString();

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
